//
//  YDNewsModel.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2018/1/22.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDNewsModel.h"

@implementation YDNewsModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{
             @"Id" : @"id"
             };
}


-(NSString *)formateTime
{
    
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    [formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [formate dateFromString:self.createTime];
    
    NSDateFormatter *formate1 = [[NSDateFormatter alloc] init];
    [formate1 setDateFormat:@"HH:mm"];
    return [formate1 stringFromDate:date];
}
-(NSAttributedString *)attr24Title
{
    return [NSString createLineWrapAttriStringWithString:self.content andLineSpace:1.2 withWrapSpace:0.3 Font:[UIFont systemFontOfSize:font14ScreenWRate * LKScreenW]];
}
//默认三行的高度
-(CGFloat)titleDefaultH
{
    return [NSString getWrapSpaceLabelHeight:@"时时时" withFont:[UIFont systemFontOfSize:font14ScreenWRate * LKScreenW] withWidth:200 andWrapSpace:0.3 withSpace:1.2] * 3;
}
-(BOOL)isToday
{
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    formate.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createtime = [formate dateFromString:self.createTime];
    if (createtime.isToday) {
        return YES;
    }else{
        return NO;
    }
}

-(NSString *)week
{
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    
    formate.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createtime = [formate dateFromString:self.createTime];
    return createtime.weekDay;
}

-(NSString *)day
{
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    formate.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createtime = [formate dateFromString:self.createTime];
    return createtime.monthDay;
}

-(CGFloat)cellH
{
    CGFloat marginLR = rate375(8);
    CGFloat marginLineLR = rate375(12);//虚线距离左边的间距
    CGFloat marginTB = isPhoneX ? rateX812(3) : rate750(3);//时间图片距离上下的边距
    
    CGFloat titleLR = rate375(12);//标题距离contentView左右距离
    CGFloat titleTB = isPhoneX ? rateX812(14) : rate750(14);//标题距离contentView上下距离
    
    //时间图片
    CGFloat timeImageX = marginLR;
    CGFloat timeImageY = marginTB;
    CGFloat timeImageW = rate375(11);
    CGFloat timeImageH = timeImageW;
    _timeImageFrame = CGRectMake(timeImageX, timeImageY, timeImageW, timeImageH);
    
    
    //时间
    CGFloat timeX = CGRectGetMaxX(_timeImageFrame) + marginLR * 0.5;
    CGFloat timeY = timeImageY;
    CGSize timeSize = [NSString sizeWithText:self.formateTime font:[UIFont systemFontOfSize:font12ScreenWRate * LKScreenW] maxSize:CGSizeMake(LKScreenW, 100)];
    CGFloat timeW = timeSize.width;
    CGFloat timeH = timeSize.height;
    _timeFrame = CGRectMake(timeX, timeY, timeW, timeH);
    
    
    if (self.isSelected) {
        //内容View
        CGFloat contentViewX = timeX;
        CGFloat contentViewY = CGRectGetMaxY(_timeFrame) + marginTB;
        CGFloat contentViewW = LKScreenW - marginLR - timeX;
        
        
        CGFloat titleX = contentViewX + titleLR;
        CGFloat titleY = contentViewY + titleTB;
        CGFloat titleW = contentViewW - titleLR * 2;
        
        CGFloat titleH = [NSString getWrapSpaceLabelHeight:self.content withFont:[UIFont systemFontOfSize:font14ScreenWRate * LKScreenW] withWidth:titleW andWrapSpace:0.3 withSpace:1.2];
        
        _attr24TitleFrame = CGRectMake(titleX, titleY, titleW, titleH);
        
        
        CGFloat contentViewH = titleH + titleTB * 2;
        _contentViewFrame = CGRectMake(contentViewX, contentViewY, contentViewW, contentViewH);
        
        
        _postImageFrame = CGRectZero;
        
    }else{

        //内容View
        CGFloat contentViewX = timeX;
        CGFloat contentViewY = CGRectGetMaxY(_timeFrame) + marginTB;
        CGFloat contentViewW = LKScreenW - marginLR - timeX;
        
        
        CGFloat titleX = contentViewX + titleLR;
        CGFloat titleY = contentViewY + titleTB;
        CGFloat titleW = contentViewW - titleLR * 2;
        CGFloat titleH = [NSString getWrapSpaceLabelHeight:self.content withFont:[UIFont systemFontOfSize:font14ScreenWRate * LKScreenW] withWidth:titleW andWrapSpace:0.3 withSpace:1.2];
        
        if (titleH <= self.titleDefaultH) {
            _attr24TitleFrame = CGRectMake(titleX, titleY, titleW, titleH);
            _postImageFrame = CGRectZero;
        }else{
            _attr24TitleFrame = CGRectMake(titleX, titleY, titleW, self.titleDefaultH);
            
            CGFloat postImageW = rate375(25);
            CGFloat postImageH = isPhoneX ? rateX812(12) : rate750(12);
            CGFloat postImageX = LKScreenW * 0.5 - postImageW * 0.5;
            CGFloat postImageY = CGRectGetMaxY(_attr24TitleFrame) + (isPhoneX ? rateX812(5) : rate750(5));
            _postImageFrame = CGRectMake(postImageX, postImageY, postImageW,postImageH);
        }
        
        
        
        CGFloat contentViewH = _attr24TitleFrame.size.height + titleTB * 2;
        _contentViewFrame = CGRectMake(contentViewX, contentViewY, contentViewW, contentViewH);
        
        
        

    }
    
//    //内容View
//    CGFloat contentViewX = timeX;
//    CGFloat contentViewY = CGRectGetMaxY(_timeFrame) + marginTB;
//    CGFloat contentViewW = LKScreenW - marginLR - timeX;
//    CGFloat contentViewH = isPhoneX ? rateX812(88) : rate750(88);
//    _contentViewFrame = CGRectMake(contentViewX, contentViewY, contentViewW, contentViewH);
    
    //虚线开始和结束位点
    _dashStartPoint = CGPointMake(marginLineLR, CGRectGetMinY(_contentViewFrame));
    _dashEndPoint = CGPointMake(marginLineLR, CGRectGetMaxY(_contentViewFrame));
    
    
    
    

    
    return CGRectGetMaxY(_contentViewFrame) + marginTB;
}

@end
